<script lang="ts" setup>
import { inject, ref } from 'vue'
import { showModalKey, keywordsKey } from '@/keys'
import type { KeywordsModal, ShowModal } from '@/keys'
import _ from 'lodash'

const showModalInject = inject<typeof ShowModal>(showModalKey)
const keywordsInject = inject<typeof KeywordsModal>(keywordsKey)

const addItem = () => {
  showModalInject.setShowModal(true)
}

const keywords = ref('')

const search = _.debounce(() => {
  keywordsInject.setKeywords(keywords.value)
}, 500)

  ; (async () => {
    await window.exposeApi.responseFromMain()
    addItem()
  })();
</script>

<template>
  <div class="search-container">
    <div class="button" @click="addItem">+</div>
    <div class="input">
      <input type="text" placeholder="请输入关键字..." @keyup="search" v-model="keywords">
    </div>
  </div>
</template>

<style lang="stylus" scoped>
div.search-container
  height 60px
  background #d3d3d3
  display flex
  align-items center
  justify-content center
  padding-left 10px
  .button
    width 40px
    height 40px
    background-color #1e90ff
    padding-left 0
    border-radius 5px
    font-size 30px
    font-weight bold
    color #fff
    text-align center
    cursor default
  .input
    flex 1
    height 36px
    padding 0 10px
    input
      height 100%
      width 100%
      outline none
      border solid 1px #ccc
      border-radius 5px
      padding 0 10px
</style>